import { Form } from 'antd';
import { ReactElement } from 'react';
import FormattedMessageCustom from '../FormattedMessageCustom/FormattedMessageCustom';
type IParams = {
    item: IBuildForm.Item;
    children: ReactElement;
    getValueFromEvent?: (e: any) => any;
};
const FormItem: React.FC<IParams> = (props) => {
    const { item, children } = props;
    let initialValue;
    if (
        item.type === 'text' ||
        item.type === 'disabled' ||
        item.type === 'rating' ||
        item.type === 'textarea'
    ) {
        initialValue = item.value ?? null;
    } else if (item.type === 'images') {
        initialValue = item.value.map((item, index) => {
            return {
                uid: index,
                name: index + '.png',
                status: 'done',
                url: item.url,
            };
        });
    } else if (item.type === 'city') {
        if (item.value) {
            initialValue = [
                {
                    label: item.value['country_name'],
                    value: item.value['country'],
                },
                {
                    label: item.value['province_name'],
                    value: item.value['province'],
                },
                {
                    label: item.value['city_name'],
                    value: item.value['city'],
                },
            ];
        }
    } else if (item.type === 'picker') {
        // initialValue = dayjs(item.value);
    } else {
        initialValue = item.value;
    }
    return (
        <Form.Item
            {...props}
            name={item.key}
            label={
                <FormattedMessageCustom
                    id={item.label}
                ></FormattedMessageCustom>
            }
            rules={[{ required: item.required }]}
            initialValue={initialValue}
        >
            {/* {JSON.stringify(initialValue)} */}
            {children}
        </Form.Item>
    );
};
export default FormItem;
